/*
 *      math.c
 *
 *      Copyright 2007 Giulio Bai <giulio@hewle.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <mathop.h>

float abs (float num)
{
	return ((num < 0) ? -num : num);
}


float pow (float num, int p)
{
	int n_pow = 0;
	
	if (p == 0) {
		return 1;
	}
	else if (p == 1) {
		return num;
	}
	
	if (p < 0) {
		n_pow = 1;
	}
	
	// make it positive
	p = abs (p);
	
	while (p > 0) {
		num *= num;
		p --;
	}
	
	return (n_pow ? 1/num : num);
}


float pow2 (float num)
{
	return pow (num, 2);
}


float cube (float num)
{
	return pow (num, 3);
}


float circle_circ (float r)
{
	return (2 * PI * r);
}


float circle_area (float r)
{
	return (pow2 (r) * PI);
}
